<template>
  <view class="invoice-form">
    <web-view src="http://xz.bwfapiao.com/50012345671180277/050003521107/050003521107_63610309.pdf?Expires=1953710854&OSSAccessKeyId=LTAIB3SkRb2V8Vu1&Signature=BXLeY%2B9J6u38jKM5j5slenaHgp8%3D" />
    <button class="invoice-submit" :disabled="submittype" type="default" @tap="onSubimt">复制链接浏览器打开下载电子发票</button>
 
  </view>
</template>
<script>
import Taro from "@tarojs/taro";
import { setGlobalData, getGlobalData } from "../../globalData.js";
import "./invoicelook.less";
import Empty from "../../components/empty/empty";
import bulterApi from "@souche2014/bulter-api";
const api = bulterApi({ partner: "IOParking" });
export default {
  data() {
    return {
      fpUrl:'',
      orderId :'',
      orderType :'',
      apiBaseUrl: process.env.IOParking.API_HOST //请求头
    };
  },
  components: { Empty },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options);
    this.orderId = options.id;
    this.orderType = options.type;
    this.wx_login();
    this.getinvoice();
  },
  onPullDownRefresh() {
    
  },
  onReachBottom() {
 
  },
  methods: {
    wx_login() {
      api
        .getUserInfo({
          scope: "all"
        })
        .then(resp => {
          if (resp.success) {
            console.log("authCode is：", resp.data);
            if (resp.data == "mock") {
              setGlobalData("openId", "oRPxj5TQ040-YRuv0v7lhRvMyRB0");
              setGlobalData("mobile", "13021250990");
              // this.initData();
              return;
            }
            this.getInfos(resp.data);
          } else {
            console.log("err is ", resp.message, "err code is ", resp.code);
          }
        });
    },
    getInfos(authCode) {
      let that = this;
      Taro.request({
        url: this.apiBaseUrl + "/weixin/souchegetuser?authCode=" + authCode,
        data: {},
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "GET",
        success(res) {
          console.log(res.data);
          if (res.data.isSuccess) {
            var userOpenId = res.data.data.openId;
            setGlobalData("openId", userOpenId);
            setGlobalData("mobile", res.data.data.phoneNum);
          
          }
        }
      });
    },
    getinvoice() {
      let that = this;  
      let base = this.apiBaseUrl;
      Taro.request({
        url: base + "/wxinvoice/ordervoice",
        data: {
          keyword: "",
          orderId: that.orderId,
          orderType: that.orderType,
          wxOpenId: getGlobalData("openId")
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
         
          if (res.data.isSuccess) {
              console.log(res);
              that.fpUrl = res.data.fpUrl;
          }
            
        }
      });
    },
  

    
   
  }
};
</script>